home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************/
- /* */
- /* rjexec.c 06/19/86 */
- /* */
- /* this is a remote job executer for the Novell networking */
- /* system. it accepts command lines from other stations and */
- /* executes them. it sends a message back to the station */
- /* that sent the job when it is finished. */
- /* */
- /* rev 1.1 07/11/86 put tell_others in a separate routine */
- /* */
- /****************************************************************/
-
- #define DELAY 1
-
- #include <string.h>
- #include "novell.h"
-
- main()
- {
- int user_no;
- int result, value, users;
- unsigned long handle;
- char station_list[32];
- int i;
- int station;
- char cmnd_line[128], message[128];
- long ltime, target_time;
- char c;
-
- printf("Remote job execution program -- Ver. 1.1\n");
- printf("For Novell Netware\n");
- printf("Copyright (c) 1986 -- Ken Hales\n\n");
-
- tell_others();
-
- printf("Waiting for a remote command (press 's' to stop this program)...\n");
-
- /********************************************************/
- /* this is an endless loop unless the operator aborts */
- /********************************************************/
-
- while(1) {
-
- /************************************************/
- /* open a message pipe for each of up to 32 */
- /* users. this is done within the loop so that */
- /* anyone who has just logged in may get in on */
- /* the action. */
- /************************************************/
-
- for (i=0; i<32; station_list[i] = ++i) ;
- pipopen(32, station_list);
-
- /************************************************/
- /* see if a message is here yet */
- /************************************************/
-
- pipread(message);
-
- /************************************************/
- /* if one is here, execute it. */
- /* otherwise, wait DELAY seconds before looping.*/
- /* check for control-C during wait. */
- /************************************************/
-
- if (message[0] != 0) {
- for (i=0; i<message[1]; i++) {
- cmnd_line[i] = message[i+2];
- }
- cmnd_line[i] = '\0';
- printf("Job from station %d: %s\n", message[0], cmnd_line);
- result = system(cmnd_line);
- printf("Job from station %d complete.\n\n", message[0]);
- sprintf(cmnd_line, "Remote job complete. Result = %d", result);
- station_list[0] = message[0];
- brdcast(1, station_list, cmnd_line);
- printf("Waiting for a remote command (press 's' to stop this program)...\n");
- } else {
- time(<ime);
- target_time = ltime + DELAY;
- while(ltime < target_time) {
- if (kbhit()) {
- c = getch();
- if ((c == 'S') || (c == 's')) {
- printf("Program has been stopped.\n");
- semclose(handle);
- exit(0);
- } else {
- printf("\007");
- }
- } else {
- time(<ime);
- }
- }
- }
- }
- }
-
- /****************************************************************/
- /* this routine is used to tell other users which station is */
- /* running this program. for lack of a better method, we use */
- /* Novell's semaphore routines to accomplish this. the only */
- /* problem with this is that the semaphore gets closed any time */
- /* a process is terminated, and we have to re-open the */
- /* semaphore. */
- /****************************************************************/
-
- tell_others()
- {
-
- int user_no;
- int result, value, users;
- unsigned long handle;
-
- /********************************************************/
- /* find out what user i am */
- /********************************************************/
-
- user_no = getusr();
-
- /********************************************************/
- /* open semaphore, set to user number */
- /********************************************************/
-
- result = semopen("rj", user_no, &handle, &users);
-
- if (result != 0) {
- printf("Problem opening semaphore: %d\n", result);
- printf("Program aborted\n");
- exit(1);
- }
-
- result = semexam(handle, &value, &users);
-
- if (value != user_no) {
- printf("Another station is already running this program.\n");
- printf("Program aborted\n");
- semclose(handle);
- exit(1);
- }
-
- }